<?php

namespace App\Http\Controllers\Traits;

use Dingo\Api\Http\Response;
use Illuminate\Validation\ValidationException;

trait UpdateResource
{
    /**
     * Resource Controller for Destrot method
     *
     * @return false|string
     * @throws ValidationException
     */
    public function update()
    {
        $data = $this->validatedAndGetInput(
            $this->try('rules', []),
            $this->try('attributes', [])
        );

        $model = $this->getResourceFromRoute();

        $this->try('updating', $model, $data);

        $model->update($data);

        $this->try('updated', $model, $data);

        return $this->success();
    }
}
